using System;
using System.Collections.Specialized;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MetaBuilders.Irc;
using MetaBuilders.Irc.Messages;

namespace MetaBuilders.NeboTests
{
	[TestClass]
	public class IgnoreTests : MessageTester
	{

		[TestMethod]
		public void SilenceTest()
		{
			String[] raws = new String[] {
				 ":mesra.kl.my.dal.net SILENCE +acidjnk!*@*"
				,":artificer!artificer@c-24-9-165-248.hsd1.co.comcast.net SILENCE +aMike!*@*"
				,":mesra.kl.my.dal.net SILENCE"
			};

			foreach ( String raw in raws )
			{
				AssertRoundTripAndType( raw, typeof( SilenceMessage ) );
			}

			SilenceMessage msg;

			msg = MessageParserService.Service.Parse( raws[ 0 ] ) as SilenceMessage;
			Assert.AreEqual( ModeAction.Add, msg.Action );
			Assert.AreEqual( "acidjnk", msg.SilencedUser.Nick );

			msg = MessageParserService.Service.Parse( raws[ 1 ] ) as SilenceMessage;
			Assert.AreEqual( ModeAction.Add, msg.Action );
			Assert.AreEqual( "aMike", msg.SilencedUser.Nick );

			msg = MessageParserService.Service.Parse( raws[ 2 ] ) as SilenceMessage;
			Assert.AreEqual( "", msg.SilencedUser.Nick );
		}

		[TestMethod]
		public void Silence271Test()
		{
			String[] raws = new String[] {
				":mesra.kl.my.dal.net 271 artificer artificer acidjnk!*@*"
			};

			foreach ( String raw in raws )
			{
				AssertRoundTripAndType( raw, typeof( SilenceReplyMessage ) );
			}

			SilenceReplyMessage msg;
			msg = MessageParserService.Service.Parse( raws[ 0 ] ) as SilenceReplyMessage;
			Assert.AreEqual( "artificer", msg.SilenceListOwner );
			Assert.AreEqual( "acidjnk", msg.SilencedUser.Nick );
		}

		[TestMethod]
		public void Silence272Test()
		{
			String[] raws = new String[] {
				":mesra.kl.my.dal.net 272 artificer :End of /SILENCE list."
			};

			foreach ( String raw in raws )
			{
				AssertRoundTripAndType( raw, typeof( SilenceEndReplyMessage ) );
			}

		}

		[TestMethod]
		public void Silence511Test()
		{
			String[] raws = new String[] {
				":mesra.kl.my.dal.net 511 artificer acidjnk!*@* :Your silence list is full"
			};

			foreach ( String raw in raws )
			{
				AssertRoundTripAndType( raw, typeof( SilenceListFullMessage ) );
			}

			SilenceListFullMessage msg;
			msg = MessageParserService.Service.Parse( raws[ 0 ] ) as SilenceListFullMessage;
			Assert.AreEqual( "acidjnk", msg.SilenceMask.Nick );
		}

		[TestMethod]
		public void AcceptListEditorTest()
		{
			String[] raws = new String[] 
			{
				":irc.pte.hu ACCEPT azure",
				":irc.pte.hu ACCEPT -BBS",
				":irc.pte.hu ACCEPT -BBS,azure"
			};

			foreach ( String raw in raws )
			{
				AssertRoundTripAndType( raw, typeof( AcceptListEditorMessage ) );
			}

			AcceptListEditorMessage msg;

			msg = MessageParserService.Service.Parse( raws[ 0 ] ) as AcceptListEditorMessage;
			Assert.AreEqual( msg.AddedNicks.Count, 1 );
			Assert.AreEqual( msg.RemovedNicks.Count, 0 );
			Assert.AreEqual( msg.AddedNicks[ 0 ], "azure" );

			msg = MessageParserService.Service.Parse( raws[ 1 ] ) as AcceptListEditorMessage;
			Assert.AreEqual( msg.AddedNicks.Count, 0 );
			Assert.AreEqual( msg.RemovedNicks.Count, 1 );
			Assert.AreEqual( msg.RemovedNicks[ 0 ], "BBS" );

			msg = MessageParserService.Service.Parse( raws[ 2 ] ) as AcceptListEditorMessage;
			Assert.AreEqual( msg.AddedNicks.Count, 1 );
			Assert.AreEqual( msg.RemovedNicks.Count, 1 );
			Assert.AreEqual( msg.AddedNicks[ 0 ], "azure" );
			Assert.AreEqual( msg.RemovedNicks[ 0 ], "BBS" );
		}

		[TestMethod]
		public void AcceptListRequestTest()
		{
			String raw = ":irc.pte.hu ACCEPT *";
			AcceptListRequestMessage msg;
			msg = AssertRoundTripAndType( raw, typeof( AcceptListRequestMessage ) ) as AcceptListRequestMessage;
		}

		[TestMethod]
		public void AcceptListReplyTest()
		{
			String raw = ":irc.pte.hu 281 artificer azure bbs";
			AcceptListReplyMessage msg;

			msg = AssertRoundTripAndType( raw, typeof( AcceptListReplyMessage ) ) as AcceptListReplyMessage;
			Assert.AreEqual( 2, msg.Nicks.Count );
			Assert.AreEqual( "azure", msg.Nicks[ 0 ] );
			Assert.AreEqual( "bbs", msg.Nicks[ 1 ] );
		}

		[TestMethod]
		public void AcceptListEndReplyTest()
		{
			String raw = ":irc.pte.hu 282 artificer :End of /ACCEPT list.";
			AssertRoundTripAndType( raw, typeof( AcceptListEndReplyMessage ) );
		}

		[TestMethod]
		public void Accept458Test()
		{
			String raw = ":irc.pte.hu 458 artificer BBS :is not on your accept list";
			AcceptDoesNotExistMessage msg = AssertRoundTripAndType( raw, typeof( AcceptDoesNotExistMessage ) ) as AcceptDoesNotExistMessage;
			Assert.AreEqual( "BBS", msg.Nick );
		}

		[TestMethod]
		public void Accept457Test()
		{
			String raw = ":irc.pte.hu 457 artificer azure :is already on your accept list";
			AcceptAlreadyExistsMessage msg = AssertRoundTripAndType( raw, typeof( AcceptAlreadyExistsMessage ) ) as AcceptAlreadyExistsMessage;
			Assert.AreEqual( "azure", msg.Nick );
		}

		[TestMethod]
		public void Accept456Test()
		{
			String raw = ":irc.server 456 client :Accept list is full";
			AssertRoundTripAndType( raw, typeof( AcceptListFullMessage ) );
		}
	}
}
